package com.guigu.equipmentservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.common.utils.R;
import com.guigu.equipmentservice.entity.Equipment;
import com.guigu.equipmentservice.entity.EquipmentImage;
import com.guigu.equipmentservice.service.EquipmentImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 设备图片
 * </p>
 *
 * @author zcy
 * @since 2025-09-28
 */
@RestController
@RequestMapping("/equipmentservice/equipmentImage")
public class EquipmentImageController {
    @Autowired
    private EquipmentImageService equipmentImageService;


    /**
     * 前台-根据当前设备id去查询当前设备下面的所有图片
     * */
    @GetMapping("/selectEquipmentImageByEqId/{id}")
    public R selectEquipmentImageByEqId(@PathVariable("id") Integer id) {

        //查询设备图片
        QueryWrapper<EquipmentImage> equipmentImageQueryWrapper = new QueryWrapper<>();
        equipmentImageQueryWrapper.eq("equipment_id", id);

        List<EquipmentImage> list = equipmentImageService.list(equipmentImageQueryWrapper);

        return R.ok().data("list", list);
    }


    /**
     * 查询每一个设备图片的第一张照片
     * @param id
     * @return
     */
    @GetMapping("/selectEquipmentImageOne/{id}")
    public EquipmentImage selectEquipmentImageOne(@PathVariable("id") Integer id) {

        //查询设备图片
        QueryWrapper<EquipmentImage> equipmentImageQueryWrapper = new QueryWrapper<>();
        equipmentImageQueryWrapper.eq("equipment_id", id);
        equipmentImageQueryWrapper.last("LIMIT 1");

        EquipmentImage one = equipmentImageService.getOne(equipmentImageQueryWrapper);

        return one;
    }
}
